package esay.array;

/**
 * 找出数组中唯一未重复出现的元素.采用异或运算
 * @author ruizhou
 * @date 24.02.2018
 */
public class SingleNumber {
    private static int singleNumber(int[] nums) {
        if (nums == null || nums.length <= 0) {
            return Integer.MIN_VALUE;
        }

        int res = nums[0];
        for (int i = 1, size = nums.length; i < size; i++) {
            res ^= nums[i];
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = {1, 1, 5, 4, 5};
        System.out.println(singleNumber(nums));
    }
}
